<?
    /* -*- Mode: PHP5; tab-width: 4; indent-tabs-mode: nil; basic-offset: 4 -*- */
    
    /*********************************************************
    *            --== InArch ==--
    * @author Kulikov Alexey <a.kulikov@gmail.com>
    * @version n/a
    * @since 16.08.2005
    * @copyright essentialmind.com 2005
    *
    *********************************************************/
    
    /***
    * Class encodingHandler
    ****
    * This is the module installer/deinstaller, shall
    * automate integration of new modules into client
    * solutions
    ****
    * @package usefulStuff
    * @author A Kulikov <a.kulikov@gmail.com>
    * @version n/a
    * @since 16.08.2005
    * @copyright essentialmind.com 2005
    ***/
    class encodingHandler{
        
        public function __construct(){
            //nathin!   
        }
        
        
        /**
         * Convert URL UTF-8 to valid UTF8
         *
         * @param string $str
         * @return string
         */
        public function unescape($str) {
            global $GLOBALS;
            
            $str = rawurldecode($str);
            preg_match_all("/(?:%u.{4})|&#x.{4};|&#\d+;|.+/U",$str,$r);
            $ar = $r[0];
            foreach($ar as $k=>$v) {
                if(substr($v,0,2) == "%u")
                    $ar[$k] = iconv("UCS-2BE","UTF-8",pack("H4",substr($v,-4)));
                elseif(substr($v,0,3) == "&#x")
                    $ar[$k] = iconv("UCS-2BE","UTF-8",pack("H4",substr($v,3,-1)));
                elseif(substr($v,0,2) == "&#") {
                    $ar[$k] = iconv("UCS-2BE","UTF-8",pack("n",substr($v,2,-1)));
                }
            }
            $title = join("",$ar);
            
            
            //if($GLOBALS['_CONFIG']['locale'] == 'de_AT.UTF-8'){
                //$string   = iconv('utf-8','iso-8859-1//IGNORE',$title);
                $string = $title;
                //echo $string;
                $string   = str_split($string);
                $toReturn = array();
                foreach($string as $key => $val){
                    $t = ord($val);
                    switch($t){
                        case 220: $toReturn[] = '&Uuml;'; break;
                        case 214: $toReturn[] = '&Ouml;'; break;
                        case 196: $toReturn[] = '&Auml;'; break;
                        case 252: $toReturn[] = '&uuml;'; break;
                        case 246: $toReturn[] = '&ouml;'; break;
                        case 228: $toReturn[] = '&auml;'; break;
                        default:  $toReturn[] = $val;
                    }
                    
                    //echo ord($val).'-'.$val.' ';
                }
                $title   = implode('',$toReturn);
            //}
            //echo $title;exit;
            return $title;
        }
    }
?>